<template>
  <div class="home-container">
    <frontend-header />
    <!-- 轮播图区域 -->
    <section class="banner-carousel">
      <el-carousel
        height="600px"
        :interval="5000"
        arrow="always"
        indicator-position="bottom"
        class="home-carousel"
      >
        <el-carousel-item>
          <div class="carousel-item">
            <img src="https://picsum.photos/1600/600?random=10" alt="在线教育课程轮播图1" class="carousel-image">
            <div class="carousel-content">
              <h1>专业技能提升</h1>
              <p>学习前沿技术，提升职业竞争力</p>
              <div class="carousel-actions">
                <router-link to="/course/list" class="btn-primary">浏览课程</router-link>
                <router-link to="/register" class="btn-secondary" v-if="!isLogin">立即注册</router-link>
              </div>
            </div>
          </div>
        </el-carousel-item>
        <el-carousel-item>
          <div class="carousel-item">
            <img src="https://picsum.photos/1600/600?random=11" alt="在线教育课程轮播图2" class="carousel-image">
            <div class="carousel-content">
              <h1>名师一对一指导</h1>
              <p>专业老师在线教学，随时解答疑惑</p>
              <div class="carousel-actions">
                <router-link to="/course/list" class="btn-primary">探索课程</router-link>
                <router-link to="/register" class="btn-secondary" v-if="!isLogin">免费试听</router-link>
              </div>
            </div>
          </div>
        </el-carousel-item>
        <el-carousel-item>
          <div class="carousel-item">
            <img src="https://picsum.photos/1600/600?random=12" alt="在线教育课程轮播图3" class="carousel-image">
            <div class="carousel-content">
              <h1>灵活学习方式</h1>
              <p>随时随地学习，自主掌控学习进度</p>
              <div class="carousel-actions">
                <router-link to="/course/list" class="btn-primary">开始学习</router-link>
                <router-link to="/register" class="btn-secondary" v-if="!isLogin">了解更多</router-link>
              </div>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </section>



    <!-- 热门课程 -->
    <section class="hot-courses">
      <div class="container">
        <div class="section-title">
          <h2>热门课程</h2>
          <p>精选优质课程，满足您的学习需求</p>
        </div>
        <div class="courses-grid">
          <div class="course-card" v-for="course in hotCourses" :key="course.hotId">
            <div class="course-image-wrapper">
              <img :src="course.hotImage" :alt="course.hotName" class="course-image">
              <div class="course-badge">热门</div>
            </div>
            <div class="course-info">
              <h3 class="course-title">{{ course.hotName }}</h3>
              <div class="course-meta">
                <span class="course-price">¥{{ course.hotPrice }}</span>
                <div class="course-stats">
                  <el-icon class="students-icon"><User /></el-icon>
                  <span>{{ course.orderCount }}人学习</span>
                </div>
              </div>
              <div class="course-actions">
                <router-link :to="'/course/detail/' + course.hotId" class="btn-outline">查看详情</router-link>
              </div>
            </div>
          </div>
        </div>
        <div class="view-all-container">
          <router-link to="/course/list" class="view-all">
            查看全部课程
            <el-icon><ArrowRight /></el-icon>
          </router-link>
        </div>
      </div>
    </section>
    <!-- 页脚 -->
    <FrontendFooter />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { CollectionTag, VideoPlay, Document, User, ArrowRight, Star, ArrowDown } from '@element-plus/icons-vue'
import { ElMessage, ElCarousel, ElCarouselItem } from 'element-plus'
import FrontendHeader from '../../components/FrontendHeader.vue'
import FrontendFooter from '../../components/FrontendFooter.vue'
import {hotCourse} from "@/api/Course.js";

const router = useRouter()
const isLogin = ref(false)
const userInfo = ref(null)
//热门课程的变量
const hotCourses = ref([])
//显示热门课程数据
const showHotCourse=()=>{
  hotCourse().then(res=>{
    hotCourses.value = res.data
  })
}

onMounted(() => {
  // 这里可以调用API获取热门课程数据
  showHotCourse()
})
</script>

<style scoped>
/* 基础容器 */
.home-container {
  min-height: 100vh;
  background-color: #f5f7fa;
  display: flex;
  flex-direction: column;
  padding-top: 0;
}

/* 通用容器样式 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 通用标题样式 */
.section-title {
  text-align: center;
  margin-bottom: 40px;
}

.section-title h2 {
  font-size: 28px;
  color: #303133;
  margin-bottom: 10px;
  position: relative;
  display: inline-block;
}

.section-title h2::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background-color: #667eea;
  border-radius: 3px;
}

.section-title p {
  color: #909399;
  font-size: 16px;
}

/* 按钮样式 */
.btn-primary {
  display: inline-block;
  padding: 10px 24px;
  background-color: #667eea;
  color: white;
  border-radius: 4px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s;
  border: none;
  cursor: pointer;
}

.btn-primary:hover {
  background-color: #5a67d8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
  display: inline-block;
  padding: 10px 24px;
  background-color: white;
  color: #667eea;
  border: 1px solid #667eea;
  border-radius: 4px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s;
  margin-left: 16px;
  cursor: pointer;
}

.btn-secondary:hover {
  background-color: #667eea;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-outline {
  display: inline-block;
  padding: 8px 16px;
  background-color: white;
  color: #667eea;
  border: 1px solid #667eea;
  border-radius: 4px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s;
  cursor: pointer;
}

.btn-outline:hover {
  background-color: #667eea;
  color: white;
}

/* 轮播图样式 */
.banner-carousel {
  position: relative;
  margin-bottom: 40px;
}

.home-carousel {
  width: 100%;
}

.carousel-item {
  position: relative;
  height: 600px;
  overflow: hidden;
}

.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

.carousel-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: white;
  z-index: 10;
  max-width: 800px;
  padding: 0 20px;
}

.carousel-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.3));
}

.carousel-content h1 {
  font-size: 56px;
  margin-bottom: 24px;
  font-weight: 800;
  letter-spacing: -1.5px;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  line-height: 1.2;
}

.carousel-content p {
  font-size: 24px;
  opacity: 0.95;
  margin-bottom: 48px;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.carousel-actions {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}

.carousel-content .btn-primary {
  padding: 16px 36px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 6px;
  background-color: white;
  color: #667eea;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  min-width: 200px;
}

.carousel-content .btn-primary:hover {
  background-color: #f8f9ff;
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  color: #667eea;
}

.carousel-content .btn-secondary {
  padding: 16px 36px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
  margin-left: 0;
  min-width: 200px;
  backdrop-filter: blur(10px);
}

.carousel-content .btn-secondary:hover {
  background-color: white;
  color: #667eea;
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  border-color: white;
}

/* Element Plus Carousel 样式覆盖 */
.home-carousel .el-carousel__arrow {
  width: 60px;
  height: 60px;
  font-size: 24px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
}

.home-carousel .el-carousel__arrow:hover {
  background-color: rgba(255, 255, 255, 0.4);
}

.home-carousel .el-carousel__indicators--bottom {
  bottom: 40px;
}

.home-carousel .el-carousel__indicator {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin: 0 10px;
}

.home-carousel .el-carousel__indicator.is-active {
  background-color: white;
  width: 40px;
  border-radius: 8px;
  transition: all 0.3s;
}

.banner .btn-secondary:hover {
  background-color: white;
  color: #667eea;
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
  border-color: white;
}

/* 已移除课程分类样式 */


/* 热门课程样式 - PC端优化 */
.hot-courses {
  padding: 100px 0;
  background-color: #f8f9fa;
  position: relative;
}

.courses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 40px;
  margin-bottom: 50px;
}

.course-card {
  background-color: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  height: 400px;
  border: 1px solid #f0f0f0;
  position: relative;
}

.course-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #667eea, #764ba2);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

.course-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.12);
}

.course-card:hover::before {
  transform: scaleX(1);
}

.course-image-wrapper {
  position: relative;
  height: 200px;
  overflow: hidden;
}

.course-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.course-card:hover .course-image {
  transform: scale(1.05);
}

.course-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background-color: #f56c6c;
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.course-info {
  padding: 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.course-title {
  margin: 0 0 16px 0;
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  line-height: 1.4;
  transition: color 0.3s;
}

.course-card:hover .course-title {
  color: #667eea;
}

.course-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.course-price {
  font-size: 24px;
  font-weight: 700;
  color: #f56c6c;
}

.course-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #909399;
  font-size: 14px;
}

.students-icon {
  font-size: 16px;
}

.course-actions {
  margin-top: auto;
}

.view-all-container {
  text-align: center;
}

.view-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #667eea;
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  padding: 12px 24px;
  border: 1px solid #667eea;
  border-radius: 6px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.view-all:hover {
  background-color: #667eea;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.3);
}

/* 平台优势部分已移除，相关样式已删除 */

/* 页脚已移至可复用组件 FrontendFooter.vue */

/* 优化PC端大屏幕体验 */
@media (min-width: 1400px) {
  .container {
    max-width: 1400px;
  }
  
  .banner h1 {
    font-size: 64px;
  }
  
  .banner p {
    font-size: 26px;
  }
  
  .courses-grid {
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 50px;
  }
  
  .categories-grid,
  .advantages-grid {
    gap: 60px;
  }
  
  .categories-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}
</style>